using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BaseData.DomainLib.AggregatesModel.CustomerAggregate;
using Microsoft.EntityFrameworkCore;
using Swimj.DomainLib.SeedWork;

namespace BaseData.InfrastructureLib.Repositories
{
    public class CustomerRepository : ICustomerRepository
    {
        private readonly BaseDataDbContext _baseDataDbContext;

        public IUnitOfWork UnitOfWork => _baseDataDbContext;

        public CustomerRepository(BaseDataDbContext baseDataDbContext)
        {
            this._baseDataDbContext = baseDataDbContext;
        }

        public Customer Add(Customer customer)
        {
            return _baseDataDbContext.Customers.Add(customer).Entity;
        }

        public async Task<Customer?> Get(int id)
        {
            return await _baseDataDbContext.Customers.FirstOrDefaultAsync(customer => customer.Id == id);
        }
    }
}